package com.kucai.yifaqapp.presenter.fragment;

import android.widget.Toast;

import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.Rekuaisufeiting;
import com.kucai.yifaqapp.model.network.entity.res.Rekuaisusaiche;
import com.kucai.yifaqapp.model.network.entity.res.ResGameDetails;
import com.kucai.yifaqapp.model.network.entity.res.ResMoney;
import com.kucai.yifaqapp.model.network.entity.res.ResSanfen;
import com.kucai.yifaqapp.model.network.entity.res.ResSetbet;
import com.kucai.yifaqapp.model.network.entity.res.Resbeijingsaiche;
import com.kucai.yifaqapp.model.network.entity.res.Resfeiting;
import com.kucai.yifaqapp.model.network.entity.res.Resmiaosusaiche;
import com.kucai.yifaqapp.model.network.entity.res.Respaoma;
import com.kucai.yifaqapp.model.network.entity.res.Resxingyunfeiting;
import com.kucai.yifaqapp.model.network.entity.res.Resxyfeiting;
import com.kucai.yifaqapp.ui.fragment.gameFragment.z_game1;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/12/10.ssaiche
 */

public class GamesaichePresenter extends BaseFragmentPresenter<z_game1> {


    public GamesaichePresenter(z_game1 mFragment) {
        super(mFragment);
    }


    //获取秒速赔率
    public void getmiaosusaicheoddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getmiaosusaicheoddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resmiaosusaiche>(mFragment) {
                    @Override
                    protected void onCustomNext(Resmiaosusaiche resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdatamiaosusaiche(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }


    //快速赛车获取赔率
    public void getkuaisusaiche(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getkuaisusaiche(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Rekuaisusaiche>(mFragment) {
                    @Override
                    protected void onCustomNext(Rekuaisusaiche resOods) {
                        if ((resOods.code + "").equals("0")) {
                            mFragment.setkuaisusaiche(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //快速飞艇获取赔率
    public void getkuaisufeiting(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getkuaisufeiting(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Rekuaisufeiting>(mFragment) {
                    @Override
                    protected void onCustomNext(Rekuaisufeiting resOods) {
                        if ((resOods.code + "").equals("0")) {
                            mFragment.setkuaisufeiting(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //幸运飞艇获取赔率
    public void getxingyunfeiting(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getxingyunfeiting(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resxingyunfeiting>(mFragment) {
                    @Override
                    protected void onCustomNext(Resxingyunfeiting resOods) {
                        if ((resOods.code + "").equals("0")) {
                            mFragment.setxingyunfeiting(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }


    //北京赛车
    public void getbeijingsaicheoddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getbeijingsaicheoddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resbeijingsaiche>() {
                    @Override
                    protected void onCustomNext(Resbeijingsaiche resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdatabeijingsaiche(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //幸运飞艇
    public void getxingyunfeitingoddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getxingyunfeitingoddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resxyfeiting>() {
                    @Override
                    protected void onCustomNext(Resxyfeiting resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setxyfeiting(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //北京快艇
    public void getkuaitingoddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getkuaitingoddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Resfeiting>() {
                    @Override
                    protected void onCustomNext(Resfeiting resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdatafeiting(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //香港跑马
    public void getxianggangpaomaoddes(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getxianggangpaomaoddes(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<Respaoma>() {
                    @Override
                    protected void onCustomNext(Respaoma resOods) {
                        if (resOods.code.equals("0")) {
                            mFragment.setdataxianggangpaoma(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }


    //三分赛车
    public void getsanfensaiche(final String gameid, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .getsanfenodds(HttpAdress.getuseAdress() + "api/m/pc/bet/getGameOdds", gameid, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResSanfen>() {
                    @Override
                    protected void onCustomNext(ResSanfen resOods) {
                        if (resOods.code == 0) {
                            mFragment.setsanfen(resOods.data);
                        } else {
                            Toast.makeText(mFragment.getContext(), "赔率获取失败，请重新进入", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //获取游戏详情
    public void getgamesdetail(String gameid) {
        HttpJsonUtils.getHttpApiInstance()
                .getgamesdetail(HttpAdress.getuseAdress() + "api/m/lottery/getNextIssue.do", gameid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResGameDetails>() {
                    @Override
                    protected void onCustomNext(ResGameDetails resGameDetails) {
                        if (null != resGameDetails.data && resGameDetails.code == 0) {
                            if ("秒速赛车".equals(resGameDetails.data.game_name) || "北京赛车".equals(resGameDetails.data.game_name)
                                    || "秒速飞艇".equals(resGameDetails.data.game_name) || "香港跑马".equals(resGameDetails.data.game_name)
                                    || "快速赛车".equals(resGameDetails.data.game_name)
                                    || "快速飞艇".equals(resGameDetails.data.game_name)
                                    || "三分赛车".equals(resGameDetails.data.game_name)
                                    || "幸运飞艇".equals(resGameDetails.data.game_name)
                                    || "台灣幸運飛艇".equals(resGameDetails.data.game_name)
                                    ) {
                                mFragment.miaosusaiche(resGameDetails);
                            } else {
                                Toast.makeText(mFragment.getContext(), "官方关闭", Toast.LENGTH_SHORT).show();
                            }

                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //获取游戏详情期数不对
    public void getgamesdetail1(String gameid) {
        HttpJsonUtils.getHttpApiInstance()
                .getgamesdetail(HttpAdress.getuseAdress() + "api/m/lottery/getNextIssue.do", gameid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResGameDetails>() {
                    @Override
                    protected void onCustomNext(ResGameDetails resGameDetails) {
                        if (null != resGameDetails.data && resGameDetails.code == 0) {
                            if ("秒速赛车".equals(resGameDetails.data.game_name) || "北京赛车".equals(resGameDetails.data.game_name)
                                    || "秒速飞艇".equals(resGameDetails.data.game_name) || "香港跑马".equals(resGameDetails.data.game_name)
                                    || "快速赛车".equals(resGameDetails.data.game_name)
                                    || "快速飞艇".equals(resGameDetails.data.game_name)
                                    || "三分赛车".equals(resGameDetails.data.game_name)
                                    || "幸运飞艇".equals(resGameDetails.data.game_name)
                                    || "台灣幸運飛艇".equals(resGameDetails.data.game_name)) {
                                mFragment.miaosusaiche1(resGameDetails);
                            } else {
                                Toast.makeText(mFragment.getContext(), "官方关闭", Toast.LENGTH_SHORT).show();
                            }

                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //下注
    public void Betbet(final String data, String token) {
        HttpJsonUtils.getHttpApiInstance()
                .Betbet(HttpAdress.getuseAdress() + "api/m/lottery/bet.do", data, token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResSetbet>(mFragment) {
                    @Override
                    protected void onCustomNext(ResSetbet resOods) {

                        if ("200".equals(resOods.code)) {
                            mFragment.betsuccses();
                        } else {
                            Toast.makeText(mFragment.getContext(), resOods.msg, Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }

    //获取余额
    public void getmoney(String token) {
        HttpJsonUtils.getHttpApiInstance()

                .getmoney(HttpAdress.getuseAdress() + "api/m/user/getMoney", token)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResMoney>() {
                    @Override
                    protected void onCustomNext(ResMoney resOods) {
                        if (resOods.code == 0) {
                            mFragment.moneychange(resOods);
                        }
                    }

                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {
                    }
                });
    }
}
